package round77;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * User: Samuel
 * Date: 07-08-11
 * Time: 09:23 AM
 */
public class B {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String orig = in.readLine();
        int oNum = Integer.parseInt(orig);
        StringBuilder num = new StringBuilder(orig);
        if (num.length() % 2 == 1) {
            num = getStr(num.length() + 1);
            System.out.println(getLowest(num));
            System.exit(0);
        }


        int totN = num.length() / 2;
        int four = 0, seven = 0;
        for (int i = 0; i < num.length(); i++) {
            if (num.charAt(i) == '4')
                four++;
            else if (num.charAt(i) == '7') {
                seven++;
            }
        }
        
        while (true) {
            boolean has = false;
            for (int i = 0; i < num.length(); i++) {
                if (num.charAt(i) > '7') {
                    has = true;
                    boolean found = false;
                    int j = i - 1;
                    for (; j >= 0; j--) {
                        if (num.charAt(j) < '9') {
                            found = true;
                            num.setCharAt(j, (char) (num.charAt(j) + 1));
                            for (int k = j + 1; k < num.length(); k++) {
                                num.setCharAt(k, '4');
                            }
                            break;
                        }
                    }
                    if (!found) {
                        num = getStr(num.length() + 2);
                        System.out.println(getLowest(num));
                        System.exit(0);
                    }
                }
                if (!has && (num.charAt(i) > '4' && num.charAt(i) < '7')) {
                    num.setCharAt(i, '7');
                    has = true;
                    for (int j = i + 1; j < num.length(); j++) {
                        num.setCharAt(j, '4');
                    }
                }
                if (!has && (num.charAt(i) >= '0' && num.charAt(i) < '4')) {
                    num.setCharAt(i, '4');
                    has = true;
                    for (int j = i + 1; j < num.length(); j++) {
                        num.setCharAt(j, '4');
                    }
                }
            }
            if (!has) break;
        }

        four = 0; seven = 0;
        for (int i = 0; i < num.length(); i++) {
            if (num.charAt(i) == '4')
                four++;
            else if (num.charAt(i) == '7') {
                seven++;
            }
        }
        boolean found = four == seven;
        while(!found) {
            int index = -1;
            for (int i = num.length() - 1; i >= 0; i--) {
                if (num.charAt(i) == '4') {
                    index = i;
                    num.setCharAt(i, '7');
                    seven++;
                    four--;
                    break;
                }
            }
            if (index != -1) {
                for (int i = index + 1; i < num.length(); i++) {
                    char c = num.charAt(i);
                    if (c == '7') {
                        num.setCharAt(i, '4');
                        seven--;
                        four++;
                    }
                }
            }
            
            if(index == -1)
                break;
            found = four== seven;
        }
        
        if (found) {
            System.out.println(num.toString());
            System.exit(0);
        } else {
            num = getStr(num.length() + 2);
            System.out.println(getLowest(num));
            System.exit(0);
        }
    }

    static StringBuilder getStr(int len) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            sb.append("1");
        }
        return sb;
    }

    static String getLowest(StringBuilder sb) {
        int num = sb.length()/2;
        int num4 = 0;
        for (int i = 0; i < num * 2; i++) {
            if(num4++<num) {
                sb.setCharAt(i,'4');
            } else{
                sb.setCharAt(i,'7');
            }
        }
        return sb.toString();
    }
}
